﻿#ifndef __MARK_LAYER_H__
#define __MARK_LAYER_H__

#include "qcustomplot.h"
#include "mark_tip.h"

class MarkPoint
{
public:
	MarkPoint();
	MarkPoint(MarkTipWidget* tip_widget, QCPGraph* graph, QPointF p, const QStringList& text);
	//默认构造时，设置对象
	void SetParameter(MarkTipWidget* tip_widget, QCPGraph* graph, QPointF p, const QStringList& text);
	//判断是否匹配
	bool MatchPointSource(const QCPGraph* graph, const QPointF p);
	//获取标签页面对象
	MarkTipWidget* GetMarkTipWidget();
	//是否匹配标签页对象
	bool MatchMarkTipWidget(const MarkTipWidget* tip_widget);
	//获取标签绑定的曲线和点
	QPair<QCPGraph*, QPointF> GetPointSource();
	//获取标签文本
	QStringList GetMarkTipText();
	//清除标签信息
	void Clear();

private:
	MarkTipWidget* tip_widget_;
	QCPGraph* graph_;
	QPointF p_;
	QStringList text_;
};

class MarkLayer
	: public QCPLayerable
{
public:
	MarkLayer(QCustomPlot *plot, QString target_layer = QString(), QCPLayerable *parent_layerable = 0);
    ~MarkLayer();

	void CreateMarkTip(QCPGraph* graph, QPointF p, const QStringList& text);//创建标签
	void SetColor(const QString& bg_color);//设置颜色
	int GetMarkTipCount();//获取已创建标签的数量
	void SetMarkTipVisible(bool visible);//设置标签tip显隐
	void RemoveOneMarkTip(MarkTipWidget* tip_widget);//移除指定标签
	void RemoveOneMarkTip(QCPGraph* graph, QPointF p);//移除指定标签
	void RemoveAllMarkTip();//移除所有标签

protected:
	virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const {}
    virtual void draw(QCPPainter * painter);

private:
	QList<MarkPoint> mark_point_list_;//标签点列表

	QColor _kMarkTipBackgroundColor;//标点标签背景色
};

#endif//__MARK_LAYER_H__
